<?php

header("Content-Type: text/html;charset=utf-8");

include("../../function/_nosql.php"); //

include("../../function/function.php");

include("../../_include.user.judge.php");

error_reporting(E_ALL);

date_default_timezone_set('Europe/London');

require_once '../Classes/PHPExcel.php';

$objPHPExcel = new PHPExcel();

$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")

							 ->setLastModifiedBy("Maarten Balliauw")

							 ->setTitle("Office 2007 XLSX Test Document")

							 ->setSubject("Office 2007 XLSX Test Document")

							 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")

							 ->setKeywords("office 2007 openxml php")

							 ->setCategory("Test result file");

$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial');

$objPHPExcel->getDefaultStyle()->getFont()->setSize(10);

//读取报名信息

$kboy_userid = $_SESSION['kboy_userid'];

$newsid = trim($_REQUEST['newsid']);

$sql = "select * from kboy_order  where  aid=$newsid  group by uid order by id desc  ";

$res = mysql_query($sql);

$objPHPExcel->getActiveSheet()->setCellValue('A1', '订单编号');

$objPHPExcel->getActiveSheet()->setCellValue('B1', '用户名');

$objPHPExcel->getActiveSheet()->setCellValue('C1', '真实姓名');

$objPHPExcel->getActiveSheet()->setCellValue('D1', '联系方式');

$objPHPExcel->getActiveSheet()->setCellValue('E1', '证件号码');

$objPHPExcel->getActiveSheet()->setCellValue('F1', '上传地');

$objPHPExcel->getActiveSheet()->setCellValue('G1', '已付金额');

$objPHPExcel->getActiveSheet()->setCellValue('H1', '费用总额');

$objPHPExcel->getActiveSheet()->setCellValue('I1', '付款状态');

$objPHPExcel->getActiveSheet()->setCellValue('J1', '报名时间');

$objPHPExcel->getActiveSheet()->setCellValue('K1', '性别');

$objPHPExcel->getActiveSheet()->setCellValue('L1', '备注');

$h=2;

while($arr=mysql_fetch_array($res)){

if($arr['order_isfull'] == 1 ){ if(getClassName("kboy_user","user_style","uid=".$kboy_userid) == 1){ $filed = "active_cva_money";}else{ $filed ='active_all_money';} }else{ $filed ='active_part_money';} 

if($arr['order_state'] == 1 ){ $paymoneys = (getClassName("kboy_forum_active",$filed,"id=".$arr['aid'])*$arr['order_num']);}else{ $paymoneys=0;} 

if(getClassName("kboy_user","user_style","uid=".$kboy_userid) == 1){$all_money = getClassName("kboy_forum_active","active_cva_money","id=".$arr['aid']);}else{ $all_money = getClassName("kboy_forum_active","active_all_money","id=".$arr['aid']);} 

if($arr['order_state'] == 0 ){
	$paystate='未付款';
}else{
	$paystate='已付款';
	if($arr['order_states'] == 5){
		$paystate = $paystate."[已退出]";
	}
} 
if($arr['order_sex'] == 1){
	$sex = '男';
}else{
	$sex = '女';
}
$objPHPExcel->getActiveSheet()->setCellValue("A".$h."", " ".$arr['order_no']."");

$objPHPExcel->getActiveSheet()->setCellValue("B".$h."", "".getClassName("kboy_user","user_nickname","uid=".$arr['uid'])."");

$objPHPExcel->getActiveSheet()->setCellValue("C".$h."", " ".$arr['order_realname']."");

$objPHPExcel->getActiveSheet()->setCellValue("D".$h."", " ".$arr['order_phone']."");

$objPHPExcel->getActiveSheet()->setCellValue("E".$h."", " ".$arr['order_idcard']."");

$objPHPExcel->getActiveSheet()->setCellValue("F".$h."", " ".$arr['order_shangche']."");

$objPHPExcel->getActiveSheet()->setCellValue("G".$h."", " ".$paymoneys."");

$objPHPExcel->getActiveSheet()->setCellValue("H".$h."", " ".($all_money*$arr['order_num'])."");

$objPHPExcel->getActiveSheet()->setCellValue("I".$h."", " ".$paystate."");

$objPHPExcel->getActiveSheet()->setCellValue("J".$h."", " ".$arr['order_addtime']."");

$objPHPExcel->getActiveSheet()->setCellValue("K".$h."", " ".$sex."");

$objPHPExcel->getActiveSheet()->setCellValue("L".$h."", " ".$arr['order_text']."");

$h++;

}

$filename = 'excel_'.$kboy_userid;

$objPHPExcel->getActiveSheet()->setTitle('Datatypes');

$objPHPExcel->setActiveSheetIndex(0);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');



$objWriter->save( str_replace('excel',$filename,str_replace('.php', '.xls', __FILE__))  );

$objPHPExcel = PHPExcel_IOFactory::load(  str_replace('excel',$filename,str_replace('.php', '.xls', __FILE__)) );



if($objPHPExcel->getActiveSheet()->toArray()){

	echo ok("生成成功","../../user_active.php");

}

else{

	echo erro('生成失败');

}

